﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace TestHiddenColumns.ListDefinition1
{
	public static class ControlCollectionExtension
	{
		public static IEnumerable<T> FindControlsRecursively<T>(this ControlCollection col) where T : Control
		{
			if (null == col) yield break;
			foreach (Control c in col)
			{
				if (typeof(T) == c.GetType()) yield return (T) c;
				if (c.HasControls())
				{
					IEnumerable<T> ret = c.Controls.FindControlsRecursively<T>();
					if (ret != null)
						foreach(Control c2 in ret) yield return (T) c2;
				}
			}
		}
	}
}